<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Zepto environment detection unit tests</title>
  <script src="../src/polyfill.js"></script>
  <script src="../src/zepto.js"></script>
  <script src="../src/detect.js"></script>
  <script src="../vendor/evidence.js"></script>
</head>
<body>
  <h1>Zepto environment detection unit tests</h1>
  <p>
    See the browser console for results.
  </p>

  <script>
    var UA = {
      WebOS_1_4_0_Pre: "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1",
      WebOS_1_4_0_Pixi: "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1",

      iOS_3_0_iPhone: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3",
      iOS_4_0_iPhone: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7",
      iOS_3_1_1_iPod: "Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_1 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7C145",
      iOS_3_2_iPad: "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B367 Safari/531.21.10",
      iOS_4_2_iPad: "Mozilla/5.0 (iPad; U; CPU OS 4_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C134 Safari/6533.18.5",
      iOS_4_3_iPhone_Simulator: "Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5",

      Android_1_5: "Mozilla/5.0 (Linux; U; Android 1.5; de-; HTC Magic Build/PLAT-RC33) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1",
      Android_2_1: "Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 Chrome/4.1.249.1025",

      BlackBerry_6_0_0_141: "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-GB) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.141 Mobile Safari/534.1+"
    };

    function detect(t, os, version, ua){
      navigator.userAgent = ua;
      t.assert($.__detect(ua)[os]);
      t.assertEqual(version, $.__detect(ua).version);
    }

    Evidence.TestCase.extend('ZeptoAjaxTest', {

      testWebOS: function(t){
        detect(t, "webos", "1.4.0", UA.WebOS_1_4_0_Pre);
        detect(t, "webos", "1.4.0", UA.WebOS_1_4_0_Pixi);
      },

      testAndroid: function(t){
        detect(t, "android", "1.5", UA.Android_1_5);
        detect(t, "android", "2.1", UA.Android_2_1);
      },

      testIOS: function(t){
        detect(t, "ios", "3.0", UA.iOS_3_0_iPhone);
        detect(t, "ios", "3.1.1", UA.iOS_3_1_1_iPod);
        detect(t, "ios", "3.2", UA.iOS_3_2_iPad);
        detect(t, "ios", "4.0", UA.iOS_4_0_iPhone);
        detect(t, "ios", "4.2", UA.iOS_4_2_iPad);

        detect(t, "ios", "4.3", UA.iOS_4_3_iPhone_Simulator);

        t.assert($.__detect(UA.iOS_3_2_iPad).ipad);
        t.assert($.__detect(UA.iOS_4_2_iPad).ipad);
        t.assert($.__detect(UA.iOS_4_0_iPhone).iphone);
        t.assert($.__detect(UA.iOS_4_3_iPhone_Simulator).iphone);
      },

      testBlackBerry: function(t) {
        detect(t, "blackberry", "6.0.0.141", UA.BlackBerry_6_0_0_141);
      }

      //, FIXME (needs code change in detect.js)
      //testBrowser: function(t){
      //  t.assert($.browser);
      //  t.assert($.browser.webkit);
      //  t.assertEqual("533.19.4", $.browser.version);
      // }
    });
  </script>
</body>
</html>
